//
//  AppDelegate.m
//  掌上还
//
//  Created by 中企互联 on 2018/1/3.
//  Copyright © 2018年 中企互联. All rights reserved.
//

#import "AppDelegate.h"
#import "XMGTabBarController.h"
#import "WYCRegisterController.h"
#import "WYCLoginController.h"
#import "IWNewfeatureViewController.h"
#import "WYCAccountTool.h"
#import "IQKeyboardManager.h"
#import "SetGestureLockViewController.h"
@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc]init];
    self.window.frame = [UIScreen mainScreen].bounds;
    
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    
    NSLog(@"\n ===> 程序开始 !");
    
    [self.window makeKeyAndVisible];
    if (@available(iOS 11.0, *)){
        [[UIScrollView appearance] setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
    }
    
    IQKeyboardManager *keyboardManager = [IQKeyboardManager sharedManager]; // 获取类库的单例变量
    
    keyboardManager.enable = YES; // 控制整个功能是否启用
    
    keyboardManager.shouldResignOnTouchOutside = YES; // 控制点击背景是否收起键盘
    
    keyboardManager.shouldToolbarUsesTextFieldTintColor = YES; // 控制键盘上的工具条文字颜色是否用户自定义
    
    keyboardManager.toolbarManageBehaviour = IQAutoToolbarBySubviews; // 有多个输入框时，可以通过点击Toolbar 上的“前一个”“后一个”按钮来实现移动到不同的输入框
    
    keyboardManager.enableAutoToolbar = NO; // 控制是否显示键盘上的工具条
    
    keyboardManager.shouldShowTextFieldPlaceholder = YES; // 是否显示占位文字
    
    keyboardManager.placeholderFont = [UIFont boldSystemFontOfSize:17]; // 设置占位文字的字体
    
    keyboardManager.keyboardDistanceFromTextField = 10.0f; // 输入框距离键盘的距离
    
    
    [self.window makeKeyAndVisible];
        if(![[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"]) {
    
            [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstLaunch"];
    
            IWNewfeatureViewController *vc = [[IWNewfeatureViewController alloc] init];
    
            self.window.rootViewController = vc;
    
        }else {
    
    if ([WYCAccountTool unarchivetoken]) {
        if (![[NSUserDefaults standardUserDefaults] boolForKey:@"first"]){
            self.window.rootViewController = [[XMGTabBarController alloc] init];
        }else{
            [self gotosetGestureLockVC];
            
        }
        
    }else{
        
        self.window.rootViewController = [[WYCLoginController alloc] init];
    }
    
     }
    return YES;
}

- (void)gotosetGestureLockVC
{
    SetGestureLockViewController * sg = [[SetGestureLockViewController alloc] init];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(InfoNotificationAction:) name:@"yes" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(InfoNotificationNO:) name:@"no" object:nil];
    self.window.rootViewController = sg;
}
- (void)InfoNotificationNO:(NSNotification *)notification{
    
    self.window.rootViewController = [[SetGestureLockViewController alloc] init];
    
}
- (void)InfoNotificationAction:(NSNotification *)notification{
    
    self.window.rootViewController = [[XMGTabBarController alloc] init];
    
}
- (void)applicationWillResignActive:(UIApplication *)application {
    NSLog(@"\n ===> 程序暂行 !");
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    NSLog(@"\n ===> 程序进入后台 !");
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    NSLog(@"\n ===> 程序进入前台 !");
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    NSLog(@"\n ===> 程序重新激活 !");
}


- (void)applicationWillTerminate:(UIApplication *)application {
    NSLog(@"\n ===> 程序意外暂行 !");
    
    
}


@end

